package com.sopaths.utility.scheduler;

import java.util.List;

import org.apache.log4j.Logger;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;

public class ScheduleInitializer {

	private Scheduler scheduler;

	private List<Schedule> schedules;

	private final Logger logger = Logger.getLogger(ScheduleInitializer.class);

	public void apply() throws SchedulerException {
		scheduler.start();
		for (Schedule schedule : schedules) {
			try {
				scheduler.scheduleJob(schedule.getJobDetail(), schedule.getTrigger());
			} catch (SchedulerException ex) {
				logger.error("An error occurred while schedule a job.", ex);
			}
		}
	}

	public Scheduler getScheduler() {
		return scheduler;
	}

	public void setScheduler(Scheduler scheduler) {
		this.scheduler = scheduler;
	}

	public List<Schedule> getSchedules() {
		return schedules;
	}

	public void setSchedules(List<Schedule> schedules) {
		this.schedules = schedules;
	}
}
